package ntd.remote.file.tool;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.ZipUtil;
import cn.hutool.log.StaticLog;

/**
 * @author: liuwenju
 * @date: 2023/6/14 11:18
 * @version: 1.0
 */
public class ToolFileZip {

    /**
     * 文件压缩字串
     * @param bytes
     * @return
     */
    public static String zip(byte[] bytes) {
        return Base64.encode(ZipUtil.zlib(bytes, 1));
    }

    /**
     * 文件解压字串
     * @param zipStr
     * @return
     */
    public static byte[] unZip(String zipStr) {
        return ZipUtil.unZlib(Base64.decode(zipStr));
    }

    public static void main(String[] args) {
        byte[] bytes = FileUtil.readBytes("C:\\Users\\17391\\Desktop\\1683179587653.png");

        StaticLog.info("Gzip[{}]", ZipUtil.gzip(bytes).length);
        StaticLog.info("zip[{}]", ZipUtil.zip(FileUtil.file("C:\\Users\\17391\\Desktop\\1683179587653.png")).length());
        StaticLog.info("zlib1[{}]", ZipUtil.zlib(bytes, 1).length);
        StaticLog.info("zlib9[{}]", ZipUtil.zlib(bytes, 9).length);

        StaticLog.info("文件压缩后长度[{}]", zip(FileUtil.readBytes("C:\\Users\\17391\\Desktop\\1683179587653.png")).length());
    }
}
